package cn.dankal.lequ.ui.customview;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.zhy.autolayout.AutoRelativeLayout;

import cn.dankal.lequ.R;

/**
 * 作者： fred on 16/4/26 13:09.
 * 邮箱：fred_kang@dankal.cn
 */
public class Tag extends AutoRelativeLayout {
    private TextView tv;
    private ImageView iv;
    private boolean showDelete;
    private String text;
    private Context context;
/*
自定义标签，动态修改删除按钮和文字
 */
    public Tag(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.Tag);
        text = typedArray.getString(R.styleable.Tag_text);
        showDelete = typedArray.getBoolean(R.styleable.Tag_showDelete, false);
        init();
    }

    public Tag(Context context) {
        super(context);
        this.context = context;
    }


    public void init() {
        LayoutInflater inflater = LayoutInflater.from(context);
        View v = inflater.inflate(R.layout.tag, this);
        tv = (TextView) v.findViewById(R.id.tv);
        iv = (ImageView) v.findViewById(R.id.iv_delete);
        tv.setText(text);
        if (showDelete == true)
            iv.setVisibility(View.VISIBLE);
        if (showDelete == false)
            iv.setVisibility(View.INVISIBLE);
    }

    public void setTagText(String s) {
        this.text=s;
    }

    public void setTagDelete(boolean b) {
        this.showDelete=b;
    }
}
